// If you have a custom title screen, this function is all that needs to be changed
// This function is called after the splash is over to decide what to do next, by default it'll proceed with 

function Splash_NextPhase
	ResetObjectEntity(object.entityPos, TypeName[Opening], 0, object.xpos, object.ypos)
	DisableDrawRealQuickBuddy = false
end function

// Everything hereon is the splash code, you shouldn't need to change this

// Array of every frame and what sprite to use
private table Splash_SpriteTable
	2, 1, 0, 1, 2, 1, 0, 2, 0, 1, 2, 0, 2, 1, 0, 1, 0, 1, 2, 1, 0, 2, 0, 2, 1, 0, 2, 0, 1, 2, 0, 2, 0, 2, 1, 0, 1, 0, 2, 0, 1, 2, 0, 2, 1, 0, 1, 2, 1, 2, 1, 0, 2, 0, 1, 2
end table

// Array of how long every frame lasts for
private table Splash_frameDelay
	64, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 4, 3, 1, 2, 3, 2, 4, 3, 3, 4, 64, 4, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 64, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 3, 2, 3, 2, 360
end table

private table MenuControl_RandomCharacters
	5 // Space
	0 // @
	4 // . and !
	1 // tiny randos
	2 // brack
end table

private table MenuControl_TinyLetterWidth
	4, 3, 4, 4, 3, 3, 4, 4, 3, 3, 3, 3, 5, 4, 4, 3, 5, 3, 3, 3, 4, 5, 5, 3, 3, 3 // upper
	4, 3, 3, 3, 3, 2, 3, 3, 1, 3, 3, 1, 5, 3, 3, 3, 4, 2, 3, 3, 3, 3, 5, 3, 3, 3 // lower
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3 // numbers
end table

event ObjectMain
	CheckEqual(MenuIntroSkip, 1)
	temp0 = checkResult
	CheckEqual(saved.beeToggle, 1)	
	temp0 |= checkResult
	if temp0 == 1
		CallFunction(Splash_NextPhase)
		object.value0 = 320
		SetClassicFade(0, 0, 0, object.value0)		
	else
		if inputPress.start == 1
			if object.state < 5
				if object.state < 2
					object.state = 2
					object.value1 = 0
					object.value0 = 320
					PlaySfx(SfxName[Select], false)		
					SetClassicFade(0, 0, 0, object.value0)
					object.frame = 0					
				else
					object.state = 5
					//object.value0 = 0
				end if	
			end if
		end if
		
		switch object.state
		case 0
			if object.value0 == 0
				PlaySfx(SfxName[Hover], false)
			end if
			object.value0++
			if object.value0 == 50
				object.value1++
				object.state++
				GetTextInfo(temp0, 10, TEXTINFO_TEXTSIZE, object.value1, 0)
				temp0 -= 3
				object.value2 = temp0
			end if
			break
		case 1
			object.value6++
			if object.value6 == 2
				object.value2--
				object.value6 = 0
				object.value5++
				if object.value5 > 35
					object.value4 += 3
				end if	
			end if	
			if object.value2 == -1
				object.value1++
				if object.value1 == 6
					object.value1 = 0
					object.value0 = 320
					SetClassicFade(0, 0, 0, object.value0)
					object.frame = 0			
					PlaySfx(SfxName[Select], false)		
					object.state = 2
				else
					object.state--
					object.value0 = 10
					object.value2 = 0
					object.value4 = 0
					object.value5 = 0
				end if	
			end if
			break
		case 2
			// Initialization phase
			object.value0 = 320
			SetClassicFade(0, 0, 0, object.value0)
			object.state++
			break
		case 3
			// Fade-in phase
			if object.value0 > 0
				object.value0 -= 8
			else
				object.state++
			end if
			SetClassicFade(0, 0, 0, object.value0)
			break
		case 4
			// Main phase

			// Move to next frame in accordance with the table
			GetTableValue(temp0, object.frame, Splash_frameDelay)
			object.value1++
			if object.value1 == temp0
				object.frame += 1
				object.value1 = 0
			end if

			// Play the jingle when the logo starts to flash
			if object.frame == 1
				if object.value0 == 0
					PlayMusic(10)
				end if
			end if

			// Fade out when on the last frame
			if object.frame == 55
				object.value0 = 0
				object.state++
			end if
			break
		case 5
			// Fade-out phase
			if object.value0 < 350
				object.value0 += 8
				SetClassicFade(0, 0, 0, object.value0)
			else
				Callfunction(Splash_NextPhase)
				SetClassicFade(0, 0, 0, 255)
			end if
			break
		end switch
	end if	
end event

event ObjectDraw
	if object.state <= 1
		if object.value0 >= 10	
			DrawRect(0, 0, 160, 60, color3, color3, color3, 256)	
			arrayPos0 = 0

			GetTextInfo(temp1, 10, TEXTINFO_TEXTSIZE, object.value1, 0)

			temp0 = 5
			temp0 -= object.value4			
			temp2 = 5
			LoadSpriteSheet("DDLCMenu/Menu.gif")
			// Now cycle through the letters in the string
			while temp1 > object.value2
				SetActivePalette(3, 0, 256)
				
				GetTextInfo(object.value3, 10, TEXTINFO_TEXTDATA, object.value1, arrayPos0)
				object.frame = object.value3

				if object.value3 >= 65
					if object.value3 <= 90
						object.frame -= 65
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.value3
						temp5 -= 65
					end if
				end if

				if object.value3 >= 97
					if object.value3 <= 122
						object.frame -= 71
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.value3
						temp5 -= 97
						temp5 += 26
					end if
				end if

				if object.value3 >= 48
					if object.value3 <= 57
						object.frame += 11
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.value3
						temp5 -= 48
						temp5 += 26
						temp5 += 26
					end if
				end if

				if object.value3 == 32
					object.frame = 58
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1
				end if

				if object.value3 == 64
					object.frame = 58
					temp0 = screen.xcenter
					temp0--
					temp3 = MenuControl_RandomCharacters
					temp5 = 1				
				end if
				if object.value3 == 46
					object.frame = 54
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				if object.value3 == 44
					object.frame = 55
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				if object.value3 == 33
					object.frame = 57
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				if object.value3 == 39
					object.frame = 56
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			

				if object.value3 == 62
					object.frame = 69
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1				
				end if			
				if object.value3 == 95
					object.frame = 72
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1				
				end if			
				if object.value3 == 40
					object.frame = 73
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if			
				if object.value3 == 41
					object.frame = 74
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if			
				if object.value3 == 91
					object.frame = 70
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if			
				if object.value3 == 93
					object.frame = 71
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if			
				if object.value3 == 61
					object.frame = 75
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1	
				end if			

				object.frame += 3

				// Now we'll start drawing
				DrawSpriteScreenXY(object.frame, temp0, temp2)

				// Move on to the next letter that we've stored
				arrayPos0++

				// Then decrease the amount of letters we have left
				temp1--

				// Finally, space out each character
				GetTableValue(temp4, temp5, temp3)
				temp0 += temp4
				temp0++
			loop		
			SetActivePalette(6, 0, 256)
		end if	
	else
		ClearScreen(1)
		LoadSpriteSheet("Title/Splash.gif")
		GetTableValue(temp0, object.frame, Splash_SpriteTable)
		SetActivePalette(6, 0, 256)
		DrawSpriteScreenXY(temp0, screen.xcenter, screen.ycenter)
		SetActivePalette(0, 0, 256)	
		temp0 = screen.xcenter
		temp0 -= 20
		temp1 = screen.ysize
		temp1 -= 32

		object.value7++
		object.value7 %= 30

		temp2 = object.value7
		temp2 /= 15
		temp2 += 79
		DrawSpriteScreenXY(temp2, temp0, temp1)
	end if
	LoadSpriteSheet("Title/Splash.gif")	
end event

event ObjectStartup
	LoadSpriteSheet("Title/Splash.gif")
	SpriteFrame(-160, -112, 320, 224, 0, 0)
	SpriteFrame(-160, -112, 320, 224, 0, 224)
	SpriteFrame(-160, -112, 320, 224, 0, 448)

		StopMusic()

	//Uppercase Tiny Font | 3-28
	temp0 = 0
	temp2 = 1
	temp3 = 242
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 5, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 6
	loop

	//Lowercase Tiny Font | 29-54
	temp0 = 0
	temp2 = 1
	temp3 = 254
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 7, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 7
	loop

	SpriteFrame(0, 0, 15, 12, 286, 255)  // 55 . small font
	SpriteFrame(0, 0, 15, 12, 302, 255)  // 56 ! small font
	SpriteFrame(0, 0, 1, 6, 52, 269) // 57 . 
	SpriteFrame(0, 0, 1, 6, 54, 269) // 58 , 
	SpriteFrame(0, 0, 1, 6, 56, 269) // 59 ' 
	SpriteFrame(0, 0, 1, 6, 58, 269) // 60 ! 	
	SpriteFrame(0, 0, 0, 0, 0, 0) // 61

	// tiny numbers 62-72
	temp1 = 0
	temp2 = 1
	while temp1 < 10
		SpriteFrame(0, 0, 5, 5, temp2, 269) 
		temp1++
		temp2 += 5
	loop

	SpriteFrame(0, 0, 3, 5, 67, 263) // 69 >
	SpriteFrame(0, 0, 2, 5, 74, 263) // 70 [
	SpriteFrame(0, 0, 2, 5, 71, 263) // 71 ]
	SpriteFrame(0, 0, 3, 5, 68, 269) // 72 _
	SpriteFrame(0, 0, 2, 5, 75, 269) // 73 (
	SpriteFrame(0, 0, 2, 5, 72, 269) // 74 )	
	SpriteFrame(0, 0, 3, 5, 67, 257) // 75 = 

	SpriteFrame(-44, -29, 88, 58, 321, 1) // 76
	SpriteFrame(-44, -29, 88, 58, 321, 60) // 77

	LoadPalette("Splash.act", 6, 50, 34, 45)
	SetMusicTrack("Splash.ogg", 10, 0)
	LoadTextFile(10, "Data/Game/SplashText.txt")
end event


event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
